const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    productInfo:null,
    banners:[],
    currentPage:1,
    imgheight:0,
    imgwidth:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    const rate = 625/750
    wx.getSystemInfo({
      success: function(res) {
        var h = res.screenWidth * rate
        that.setData({
          imgwidth:res.screenWidth,
          imgheight:h
        })
      },
    })

    var obj = JSON.parse(options.obj)

    that.getProuductInfo(obj)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  swiperDidChange:function(e){
    console.log(e.detail)

    let current = (e.detail.current + 1).toString()
    let total = String(this.data.banners.length)

    this.setData({
      currentPage:current + "/" + total
    })
  },
  getProuductInfo: function (obj) {
    var that = this
    wx.request({
      url: app.net.baseURL + '/api/product/queryProductInfo',
      header: app.net.header,
      method: 'POST',
      data: {
        "productType": obj.productType,
        "materielModelId": obj.modelId
      },
      success: function (res) {
        console.log(res)

        that.setData({
          productInfo: res.data.data,
          banners: res.data.data.materieData.attaList,
          currentPage: "1/" + res.data.data.materieData.attaList.length
        })
      },
      fail: function (e) {
        console.log(e)
      }
    })
  }
})